using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterDisplayView : MonoBehaviour
{
	public enum ViewType
	{
		ProfileView = 0,
		IntroView = 1,
		NameSelectView = 2
	}

	[Serializable]
	public class CustomisationView
	{
		public ViewType type;

		public Transform cameraTransform;

		public CharacterRotationController.RotationControllerSettings settings;
	}

	public Transform player;

	public List<CustomisationView> views = new List<CustomisationView>();

	public Transform customisationCamera;

	public Transform cameraLeader;

	public Transform uiBackground;

	public Transform carbonPanelRotator;

	public Transform gameTransform;

	public Transform environment;

	public Transform all;

	public CharacterRotationController rotationController;

	private CustomisationView GetView(ViewType viewType)
	{
		foreach (CustomisationView view in views)
		{
			if (view.type == viewType)
			{
				return view;
			}
		}
		return null;
	}

	public void ShowView(ViewType viewType, bool rotationEnabled = true)
	{
		CustomisationView view = GetView(viewType);
		if (view != null)
		{
			cameraLeader.position = view.cameraTransform.position;
			cameraLeader.rotation = view.cameraTransform.rotation;
			rotationController.SetRotationEnabled(customisationCamera.GetComponent<Camera>(), cameraLeader, view.settings, rotationEnabled);
		}
	}

	public void ShowView(Vector3 position, Quaternion rotation, CharacterRotationController.RotationControllerSettings settings, bool isEnabled)
	{
		cameraLeader.position = position;
		cameraLeader.rotation = rotation;
		rotationController.SetRotationEnabled(customisationCamera.GetComponent<Camera>(), cameraLeader, settings, isEnabled);
	}

	public void ShowAll(float cameraWidth = 1f)
	{
		SetCameraWidth(cameraWidth);
		all.gameObject.SetActive(true);
		environment.gameObject.SetActive(true);
		UICamera.mainCamera.clearFlags = CameraClearFlags.Depth;
		customisationCamera.GetComponent<Camera>().clearFlags = CameraClearFlags.Color;
		uiBackground.gameObject.SetActive(false);
		gameTransform.gameObject.SetActive(false);
	}

	public void HideGame()
	{
		if (gameTransform != null && gameTransform.gameObject != null)
		{
			gameTransform.gameObject.SetActive(false);
		}
	}

	public void ShowGame()
	{
		all.gameObject.SetActive(false);
		uiBackground.gameObject.SetActive(false);
		gameTransform.gameObject.SetActive(true);
	}

	public void ShowUIBackground()
	{
		all.gameObject.SetActive(false);
		environment.gameObject.SetActive(false);
		UICamera.mainCamera.clearFlags = CameraClearFlags.Depth;
		customisationCamera.GetComponent<Camera>().clearFlags = CameraClearFlags.Color;
		uiBackground.gameObject.SetActive(true);
		gameTransform.gameObject.SetActive(false);
	}

	public void SetCameraWidth(float cameraWidth)
	{
		Debug.Log("Camera Width " + cameraWidth);
		Camera component = customisationCamera.GetComponent<Camera>();
		Debug.Log("CAMERA " + (component != null) + " Name " + component.gameObject.name);
		Rect rect = component.rect;
		rect.width = cameraWidth;
		component.rect = rect;
		UICamera.mainCamera.clearFlags = CameraClearFlags.Depth;
	}

	public void ShowCharacter(float cameraWidth = 1f)
	{
		SetCameraWidth(cameraWidth);
		all.gameObject.SetActive(true);
		environment.gameObject.SetActive(false);
		customisationCamera.GetComponent<Camera>().clearFlags = CameraClearFlags.Depth;
		uiBackground.gameObject.SetActive(true);
		gameTransform.gameObject.SetActive(false);
	}

	public void Hide()
	{
		if (all != null && all.gameObject != null)
		{
			all.gameObject.SetActive(false);
		}
		if (environment != null && environment.gameObject != null)
		{
			environment.gameObject.SetActive(false);
		}
		ShowCarbonPanel(true);
	}

	public void ShowCarbonPanel(bool show)
	{
		StopAllCoroutines();
		StartCoroutine(DoShowCarbonPanel(show));
	}

	private IEnumerator DoShowCarbonPanel(bool show)
	{
		Quaternion startRotation = carbonPanelRotator.localRotation;
		Quaternion endRotation = ((!show) ? Quaternion.Euler(Vector3.up * 90f) : Quaternion.identity);
		float time = 0f;
		float duration = 0.5f;
		while (time < duration)
		{
			time += RealTime.deltaTime;
			float normTime = time / duration;
			carbonPanelRotator.localRotation = Quaternion.Lerp(startRotation, endRotation, normTime);
			yield return null;
		}
		carbonPanelRotator.localRotation = endRotation;
	}
}
